package com.tbvtc.agriculturalcreditchainserver2025.service.impl;

import com.tbvtc.agriculturalcreditchainserver2025.mapper.LoginMapper;
import com.tbvtc.agriculturalcreditchainserver2025.pojo.RoleAddress;
import com.tbvtc.agriculturalcreditchainserver2025.properties.ContractAdressProperties;
import com.tbvtc.agriculturalcreditchainserver2025.service.LogisticsService;
import com.tbvtc.agriculturalcreditchainserver2025.service.PestService;
import com.tbvtc.agriculturalcreditchainserver2025.utils.BlockBaseUtils;
import com.tbvtc.agriculturalcreditchainserver2025.utils.BlockchainUtils;
import com.tbvtc.agriculturalcreditchainserver2025.utils.UserType;
import com.tbvtc.agriculturalcreditchainserver2025.vo.LogisticsVo.updateLogisticsInfoVo;
import com.tbvtc.agriculturalcreditchainserver2025.vo.Pest.getCropPestReportVo;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogisticsServiceImpl implements LogisticsService {
    @Autowired
    private BlockchainUtils blockchainUtils;
    @Autowired
    private BlockBaseUtils blockBaseUtils;
    @Autowired
    private ContractAdressProperties contractAdressProperties;
    @Autowired
    private RoleAddress roleAddress;
    @Autowired
    private LoginMapper loginMapper;


//    @Override
//    public void pdateLogisticsInfo(updateLogisticsInfoVo updateLogisticsInfoVo) {
//         blockchainUtils.sendTransaction(" LogisticContract","updateLogisticsInfo",)
//    }

    @Override
     public TransactionResponse updateLogisticsInfo(updateLogisticsInfoVo updateLogisticsInfoVo) throws Exception {
        List<Object> list = List.of(updateLogisticsInfoVo.getOrderId(),updateLogisticsInfoVo.getTrackingNumber(),
        updateLogisticsInfoVo.getStatus(),updateLogisticsInfoVo.getLocation());
        TransactionResponse response = blockchainUtils.sendTransaction("LogisticContract", "updateLogisticsInfo", contractAdressProperties.getLogisticContractAddress(), list, blockBaseUtils.getPemFilePath(UserType.LOGISTIC));
        loginMapper.updateLogisticsInfo(updateLogisticsInfoVo.getTrackingNumber(),updateLogisticsInfoVo.getOrderId());
        return response;
    }

    @Override
    public List logisticsInfo(Integer id) throws Exception {
        List<Object> list = List.of(id);
        List<Object> list1 = blockchainUtils.callContract("LogisticContract", "logisticsInfos", contractAdressProperties.getLogisticContractAddress(), list, blockBaseUtils.getPemFilePath(UserType.LOGISTIC));
        return list1;
    }


}

